<?
session_start();
require_once 'utils/user.php';
ManageUser::doLogin();

$needRecheck = false;
$m = ManageUser::doSignup();
if ($m->hasMessage()) {
    if ($m->pollMessageByCode(501)) {
        SessionMsg::pushMessage('Sign up succeed, welcome! '.$_SESSION["login"],MSG_HEAD);
        Client::showUri('index.php');
    } else {
        $needRecheck=true;
    }
}




?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
        <link rel="stylesheet" type="text/css" href="css/all.css"/>
        <style>
            /*error message*/
            #error_message {width:300px;margin:0px auto 3px auto;padding:4px;background: lightpink;border:1px solid chocolate;}
            /*signup_form format*/
            #signup_form table {margin:0px auto;border:1px solid cadetblue;}
            #signup_form table td {padding:3px;}
            #signup_form table input[type="text"],#signup_form table input[type="password"] {width:202px;height:30px;padding:0px 3px;}
            #signup_form table tr:nth-last-of-type(odd) {/*background-color: beige*/}
            #signup_form table tr:nth-last-of-type(even) {/*background-color: azure*/}
            #signup_form table col:first-of-type {background-color: beige;width:100px;}
            #signup_form table col:last-of-type {background-color: azure;}
            #signup_form table td:first-child {padding-right: 10px;text-align: right;vertical-align: top;line-height:30px;}
            #signup_form table img {border:1px solid #CCCCCC}
            #signup_form table tr:last-of-type td {text-align: left;}
            #signup_form table tr:last-of-type {background-color: white;}

        </style>
    </head>
    <body>
        <? if (SessionMsg::hasMessage()) foreach (SessionMsg::pollMessageByCode(MSG_HEAD) as $message) {echo $message;} ?>
        <?if ($needRecheck) {?>
        <div id="error_message">Please check:
            <ul>
        <?foreach ($m->pollAllMessages() as $singleMessage) {
            echo "<li>".$singleMessage;
        }?>
            </ul>
        </div>
        <?}?>
        
        <form action="signup.php?signup" method="post" id="signup_form">
            <table cellspacing="0">
                <col/><col/>
            <tr><td>Username:<td>
                    <input type="text" name="login" value="<?=isset($_POST["login"])?$_POST["login"]:""?>"/>
            <tr><td>Password:<td><input type="password" name="pwd" value="<?=isset($_POST["pwd"])?$_POST["pwd"]:""?>"/><br/>At least 6 caracters.
            <tr><td>Surname<td><input type="text" name="sn" value="<?=isset($_POST["sn"])?$_POST["sn"]:""?>"/>
            <tr><td>Given name:<td><input type="text" name="gn" value="<?=isset($_POST["gn"])?$_POST["gn"]:""?>"/>
            <tr><td>Birthday:<td><input type="text" name="bd" value="<?=isset($_POST["bd"])?$_POST["bd"]:""?>"/><br/>format: YYYY-MM-DD.
            <tr><td>Email<td><input type="text" name="email" value="<?=isset($_POST["email"])?$_POST["email"]:""?>"/>
            <tr><td>Captcha:<td><input type="text" name="code"/><br/><img src="captcha.php"/>
            <tr ><td colspan="2"><input name="submit" type="submit" value="signup"/>
            </table>
        </form>
    </body>
</html>
